In this notebook, we're looking at keypoint detection, specifically:

  • plot a histogram for the no of detected keypoints for each detector, for all images, to get a rough idea of what the default detector thresholds produce.

In [1]:
import neukrill_net.utils
import neukrill_net.image_features
import sys
import numpy as np
import skimage
import PIL.Image
import cv2
from IPython.display import display
from IPython.display import Image
import matplotlib.cm as cm

In [2]:
%matplotlib inline
import matplotlib.pyplot as plt

In [3]:
cd ..


/media/dragos/6c25c80a-cce2-4fc8-97ae-fdc11725c266/Projects/Neuroglycerine/NDSB/neukrill-net-work

In [4]:
# Load the settings 
settings = neukrill_net.utils.Settings("settings.json")

In [5]:
# Load raw training data
rawdata, labels = neukrill_net.utils.load_rawdata(settings.image_fnames, classes=settings.classes)

In [7]:
# Test the images are loaded
plt.imshow(rawdata[0], cmap = plt.get_cmap('gray'))


Out[7]:
<matplotlib.image.AxesImage at 0x7ffd0195e9d0>

Keypoint Detectors

Loop through images, detect keypoints, output histogram with no of keypoints detected

FAST


In [19]:
# FAST detector
no_of_keypoints = []
for image in rawdata:
    no_of_keypoints.append(len(neukrill_net.image_features.get_FAST_keypoints(image)))
no_of_keypoints = np.array(no_of_keypoints)

In [27]:
x = np.where(no_of_keypoints==0)
print "Number of images with no keypoints:", len(x)
plt.imshow(rawdata[x[0]], cmap = plt.get_cmap('gray'))


Number of images with no keypoints: 1
Out[27]:
<matplotlib.image.AxesImage at 0x7ffcfaadec10>

In [38]:
no_of_keypoints = no_of_keypoints[no_of_keypoints>0]
#_=plt.hist(no_of_keypoints, bins= 100)
_=plt.hist((no_of_keypoints), bins=np.logspace(0,6,50))
plt.xscale("log")


ORB


In [54]:
# ORB detector
no_of_keypoints = []
for image in rawdata:
    no_of_keypoints.append(len(neukrill_net.image_features.get_ORB_keypoints(image)))


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-54-e4a684b4bb31> in <module>()
      5 
      6 no_of_keypoints = no_of_keypoints[no_of_keypoints>0]
----> 7 print(no_of_keypoints.size)

AttributeError: 'int' object has no attribute 'size'

In [51]:
no_of_keypoints = no_of_keypoints[no_of_keypoints>0]

no_of_keypoints = np.array(no_of_keypoints)
x = np.where(no_of_keypoints==0)
print x[0]
print "Number of images with no keypoints:", len(x)
plt.imshow(rawdata[x[0]], cmap = plt.get_cmap('gray'))


[]
Number of images with no keypoints: 1
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-51-4d680105c3d2> in <module>()
      3 print x[0]
      4 print "Number of images with no keypoints:", len(x)
----> 5 plt.imshow(rawdata[x[0]], cmap = plt.get_cmap('gray'))

TypeError: only integer arrays with one element can be converted to an index

In [46]:
no_of_keypoints = no_of_keypoints[no_of_keypoints>0]
#_=plt.hist(no_of_keypoints, bins= 100)
_=plt.hist((no_of_keypoints), bins=np.logspace(0,6,50))
plt.xscale("log")



In [ ]: